package cn.shujuhai.common.controller.common;

import cn.dev33.satoken.annotation.SaCheckLogin;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController()
public class ConfigController {


    @Value("${server.servlet.context-path}")
    private String base;


    @SaCheckLogin
    @GetMapping("/config")
    public Map<String, Object> getConfig() {
        Map<String, Object> config = new HashMap<>();

        // logo 配置
        Map<String, String> logo = new HashMap<>();
        logo.put("title", "内容管理系统");
        logo.put("image", base + "pear/admin/images/logo.png");
        config.put("logo", logo);

        // menu 配置
        Map<String, Object> menu = new HashMap<>();
        menu.put("data", base + "user/getUserMenuByPerm");
        menu.put("method", "GET");
        menu.put("accordion", true);
        menu.put("collapse", false);
        menu.put("control", false);
        menu.put("select", "10");
        menu.put("async", true);
        config.put("menu", menu);

        // tab 配置
        Map<String, Object> tab = new HashMap<>();
        tab.put("enable", true);
        tab.put("keepState", true);
        tab.put("session", false);
        tab.put("preload", true);
        tab.put("max", "30");

        Map<String, String> index = new HashMap<>();
        index.put("id", "10");
        index.put("href", base + "page/common/console/console1");
        index.put("title", "首页");
        index.put("type", "_iframe");
        tab.put("index", index);

        config.put("tab", tab);

        // theme 配置
        Map<String, String> theme = new HashMap<>();
        theme.put("defaultColor", "2");
        theme.put("defaultMenu", "dark-theme");
        theme.put("defaultHeader", "light-theme");
        theme.put("allowCustom", "true");
        theme.put("banner", "false");
        config.put("theme", theme);

        // colors 配置
        List<Map<String, String>> colors = List.of(
                Map.of("id", "1", "color", "#2d8cf0", "second", "#ecf5ff"),
                Map.of("id", "2", "color", "#36b368", "second", "#f0f9eb"),
                Map.of("id", "3", "color", "#f6ad55", "second", "#fdf6ec"),
                Map.of("id", "4", "color", "#f56c6c", "second", "#fef0f0"),
                Map.of("id", "5", "color", "#3963bc", "second", "#ecf5ff")
        );
        config.put("colors", colors);

        // other 配置
        Map<String, Object> other = new HashMap<>();
        other.put("keepLoad", "1200");
        other.put("autoHead", false);
        other.put("footer", false);
        config.put("other", other);

        // header 配置
        Map<String, String> header = new HashMap<>();
//        header.put("message", base + "pear/admin/data/message.json");
        config.put("header", header);

        return config;
    }


}
